<?php
namespace app\shop\model;


use think\Model;

class PinModel extends Model
{
    protected $table = 'dp_pin';
    protected $pk = 'id';
    protected $field = true;

    public function goods()
    {
        return $this->hasOne('GoodsModel','id','goods_id');
    }

    public static function getAllList()
    {
        $list = self::with('goods')->paginate(10);
        foreach ($list as $k=>$v){
            $list[$k]['goods_name'] = $v['goods']['name'];
        }
        return $list;
    }

    public static function getOne($id)
    {
        return self::where('id', $id)->find();
    }

    public static function store($data, $id=0)
    {
        if($id == 0){
            return self::insert($data);
        }else{
            return self::where('id', $id)->update($data);
        }
    }

    public static function del($id)
    {

        return self::where('id', $id)->delete();
    }

}